{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Getting started with IonQ and JSON on Azure Quantum\n",
    "\n",
    "This notebook shows how to send a basic quantum circuit expressed using the [IonQ JSON spec](https://docs.ionq.com/#tag/quantum_programs) to a Quantinuum target via the Azure Quantum service."
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "First, install `azure-quantum` and optionally `matplotlib` for plotting:"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "# To install the Azure Quantum client package, uncomment and run the line below:\n",
    "#\n",
    "# !pip install azure-quantum==0.19.2109.165653 --quiet\n",
    "#\n",
    "# We also recommend installing matplotlib, if you don't have it installed already:\n",
    "# !pip install matplotlib --quiet"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Connecting to the Azure Quantum service\n",
    "\n",
    "To connect to the Azure Quantum service, find the resource ID and location of your Workspace from the Azure portal here: https://portal.azure.com. Navigate to your Azure Quantum workspace and copy the values from the header.\n",
    "\n",
    "<img src=\"../azure-quantum-resource-id.png\" alt=\"How to retrieve the resource ID and location from an Azure Quantum workspace\">"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "from azure.quantum import Workspace\n",
    "from azure.quantum.target import IonQ\n",
    "\n",
    "# Enter your workspace details here\n",
    "# Find your resource ID and location via portal.azure.com\n",
    "workspace = Workspace(\n",
    "    resource_id=\"\",\n",
    "    location=\"\"\n",
    ")"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "Use `workspace.get_targets` to see what targets are currently available for the Quantinuum provider, including wait times. Running this method will trigger authentication to your Microsoft account, if you're not already logged in."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "workspace.get_targets(provider_id=\"ionq\")"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[<Target name=\"ionq.qpu\", avg. queue time=54 s, Available>,\n",
       " <Target name=\"ionq.simulator\", avg. queue time=0 s, Available>]"
      ]
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "# See https://docs.ionq.com/#tag/quantum_programs for JSON format spec\n",
    "circuit = {\n",
    "    \"qubits\": 3,\n",
    "    \"circuit\": [\n",
    "        {\n",
    "        \"gate\": \"h\",\n",
    "        \"target\": 0\n",
    "        },\n",
    "        {\n",
    "        \"gate\": \"cnot\",\n",
    "        \"control\": 0,\n",
    "        \"target\": 1\n",
    "        },\n",
    "        {\n",
    "        \"gate\": \"cnot\",\n",
    "        \"control\": 0,\n",
    "        \"target\": 2\n",
    "        },\n",
    "    ]\n",
    "}"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Run on IonQ Simulator"
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "Submit the circuit to the IonQ Simulator target. The following example uses the IonQ simulator, which returns a Job object. For more information, see [Azure Quantum Job](https://review.docs.microsoft.com/azure/quantum/optimization-job-reference)."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "target = IonQ(workspace=workspace, name=\"ionq.simulator\")\n",
    "job = target.submit(circuit)"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "job.id"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'628e950a-1d85-11ec-910f-70bc105c1854'"
      ]
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "Wait until the job is complete and then fetch the results."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "source": [
    "results = job.get_results()\n",
    "results"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "...."
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "{'duration': 6075357, 'histogram': {'0': 0.5, '7': 0.5}}"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "metadata": {
    "scrolled": true
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "You can then visualize the results using [Matplotlib](https://matplotlib.org/stable/users/installing.html)."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "%matplotlib inline\n",
    "import pylab as pl\n",
    "pl.rcParams[\"font.size\"] = 16\n",
    "# The histogram returned by the results can be sparse, so here we add any of the missing bitstring labels.\n",
    "hist = {format(n, \"03b\"): 0 for n in range(8)}\n",
    "hist.update({format(int(k), \"03b\"): v for k, v in results[\"histogram\"].items()})\n",
    "pl.bar(hist.keys(), hist.values())\n",
    "pl.ylabel(\"Probabilities\")"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Probabilities')"
      ]
     },
     "metadata": {},
     "execution_count": 10
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ],
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAD9CAYAAACSoiH8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYGElEQVR4nO3dfbRldX3f8fcHiApIdBCsrWEYJhh0qJplJoaGKMhqKkYDcaHVZcqTBtClRvJgqpVoRGJjNECibQr4lCKtrlKaQdAEw9OyRJKgVuqQCugM4FM7wMiTSAS//WOfGw6Xc+/de999zz0zvF9rnXXP/e392+d7t4f5uB9+v52qQpKkrnZZ7QIkSTsmA0SS1IsBIknqxQCRJPVigEiSetlttQuYpn322afWrVu32mVI0g7ji1/84u1Vte+kZY+pAFm3bh3XXXfd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54ytdzHwBeATSd5Kc5j+dppzpn84t1JV/a8knwLOTvJjPDxB5AHAr65mbQCj/+j3BZ42atqY5N5R7ReuQG0keQmwJzA3UvmwJPsA91XVZ0efvRr7rVVto/WG2m9z23vF6O3PjH6+JMk2YFtVXc3qfN8GrW20rWnvt9X4vg1a22i9QfdbJ9MacLKzvIC1wH8H7gbuAf6ceYOARuvtDXyU5vzo94HLgedOWG934Ezgu8APgL9hgQFDq1DbVTT/oD7qtYK1bV3gM7fOwH5rW9tg+220vYnbAq5aze/bCtS2Gvtt6t+3Faht0P3W5eVkipKkXrwGIknqxQCRJPVigEiSejFAJEm9GCCSpF4MEElSLwaIJKkXA0SS1Mv/B4AkSA1p0QNPAAAAAElFTkSuQmCC"
     },
     "metadata": {
      "needs_background": "light"
     }
    }
   ],
   "metadata": {
    "scrolled": true
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### Run on IonQ QPU\n",
    "\n",
    "#### Note: The time required to run a circuit on the QPU may vary depending on current queue times."
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "Submit the circuit to the IonQ QPU target."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "qpu_target = IonQ(workspace=workspace, name=\"ionq.qpu\")\n",
    "qpu_job = qpu_target.submit(circuit)\n",
    "qpu_job.id"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'7a14dd3e-fa72-11eb-83af-00155df1914a'"
      ]
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "Wait until the job is complete and then fetch the results."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "results = qpu_job.get_results()\n",
    "results"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "{'histogram': {'0': 0.59, '2': 0.01, '3': 0.03, '7': 0.37}}"
      ]
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "markdown",
   "source": [
    "Plot the results."
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "source": [
    "pl.rcParams[\"font.size\"] = 16\n",
    "hist = {format(n, \"03b\"): 0 for n in range(8)}\n",
    "hist.update({format(int(k), \"03b\"): v for k, v in results[\"histogram\"].items()})\n",
    "pl.bar(hist.keys(), hist.values())\n",
    "pl.ylabel(\"Probabilities\")"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Probabilities')"
      ]
     },
     "metadata": {},
     "execution_count": 11
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ],
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAD9CAYAAACSoiH8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAAWnklEQVR4nO3de7SldX3f8feHwQsIUa5NNcJhhKUMFdNkmmCMiqykoBjQRVJdicqlAhqlUldMoHhFQiEaJUqTijcM0IYloYKiBuW2UiNtRqzUwYjIDHjBOsDITUQw3/7x7ONs9pzLfp7znHP2Yd6vtfba+/yey/7uhwc+PJff70lVIUlSW9stdwGSpJXJAJEkdWKASJI6MUAkSZ0YIJKkTrZf7gKW0u67715TU1PLXYYkrRhf+cpX7qyqPWaatk0FyNTUFOvWrVvuMiRpxUhy22zTlvwUVpKnJ7kkyT1J7k1yaZK9Wiy/f5JPJrkzyYNJvpnkTYtZsyRpa0t6BJJkR+Bq4CHgaKCAM4BrkhxYVQ/Ms/zawfLXAq8F7gH2A3ZaxLIlSTNY6lNYxwOrgWdW1S0ASW4EvgWcCLxvtgWTbAf8NXBVVb18aNI1i1euJGk2S30K6wjg+unwAKiqDcCXgC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o6V9BsWhQEiSerEAGln3MEg5xv4cfOY87UZILLv2vq0kEE0Z1vfUwZ3lI2uDxZnu02ycfejPrdb37VNsun9YPR3rKTfsCgMkHbGHQxyrvlury297vscILLv2vq0kEE0Z1vfE2huXRxdHy3X2Xdty2Hc/ajP7dZ3bZNs+lrH6H6ymNttRTBA2hl3MMjLgacleeHQfL8A/M7IfH0OENl3bX1ayCCaM/k8zZ09fzDS/irg64O7qJartuUw7n7U53bru7ZJ9mWa23Vn2m5309yxt016zD9QqmcfBt4IXJZkeDDI79B0Mpp2Oc1Od2GSt9AcAp9KM8bXn03PVFVfTXIxcE6Sx7FlgMh92HpnXdLaAAYhswfwi4OmtUnuH9R+ySLURpIXA08CpnvGvzDJ7sADVfW5wXf/MMn7gFOT3AfcQPMfpENobhtto9faBvOtBabY8j9oa5L87uDzZ2e4I2lOQ8v+6uD9xUk2AZuq6rpx96Oet1uvtQ3WtaTbbTDPvPt4VT2c5G00HQe/B3yRZpsdB5xUVT9tU1eftQ3mW8OWo6EdgL2H1n9dVW1qW9/YlqrDyWPlBexF0xv1XuA+ml6zUzPMtytNR6O7gR/TdNZ6zgzz7QC8D/gB8BPgfzFLB7VlqO1amv+gbvVaxNo2zvKdG0fmW0UzovNtNLem3gj87iJvt3FrO3+27TbTeseob7Z1Xdt2P+pzuy1Cbcux3cbex4ETaQaCfQj4FvCHi7zdxqqNZmSB2da31Xbu8+VgipKkTrwGIknqxACRJHVigEiSOjFAJEmdGCCSpE4MEElSJwaIJKkTA0SS1Mn/B1qthpgjIontAAAAAElFTkSuQmCC"
     },
     "metadata": {
      "needs_background": "light"
     }
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [],
   "outputs": [],
   "metadata": {}
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}